import sensor
import image
import lcd
import time
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_auto_gain(0)
sensor.set_hmirror(1)
sensor.set_vflip(1)
sensor.run(1)

green_threshold   =(16, 80, -7, 11, -9, 13)

def find_max(blobs):
    max_size=0
    for blob in blobs:
        if blob[2]*blob[3] > max_size:
            max_blob=blob
            max_size = blob[2]*blob[3]
    return max_blob

while True:
    img=sensor.snapshot()
    blobs = img.find_blobs([green_threshold])
    maxb_index=find_max(blobs)
    b=find_max(blobs)#即可得到最大色块
    tmp=img.draw_rectangle(b[0:4])
    tmp=img.draw_cross(b[5], b[6])
    c=img.get_pixel(b[5], b[6])
    print(blobs)
    lcd.display(img)
